Skip to content

regex: change old-style definitions#463

Open
oI0ck wants to merge 2 commits intomasterfrom
michal.lach/knrregex
Open

regex: change old-style definitions#463
oI0ck wants to merge 2 commits intomasterfrom
michal.lach/knrregex

Conversation

@oI0ck
Copy link
Member

@oI0ck oI0ck commented Mar 3, 2026

We use a regex implementation from one of BSD's, and it contains old-style definitions which are being slowly dropped from newer compilers.

JIRA: RTOS-1233

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the C function declarations within the regex library to adhere to contemporary ANSI C standards. The primary goal is to improve code maintainability and ensure compatibility with modern compilers, preventing potential build failures or warnings related to deprecated syntax. This change systematically updates function signatures to include parameter types directly in the function declaration, moving away from the older K&R style.

Highlights

  • Code Modernization: Updated numerous function definitions and prototypes from old-style K&R C to modern ANSI C style across the regex implementation files.
  • Compiler Compatibility: Addressed compatibility issues with newer compilers that are gradually dropping support for old-style C definitions.
Changelog
  • regex/collate.c
    • Updated function definitions for __collate_load_tables, __collate_substitute, __collate_lookup, and __collate_strdup to ANSI C style.
  • regex/collate.h
    • Updated function prototypes for __collate_strdup, __collate_substitute, __collate_load_tables, and __collate_lookup to ANSI C style.
  • regex/collcmp.c
    • Updated the function definition for __collate_range_cmp to ANSI C style.
  • regex/engine.c
    • Updated function definitions for matcher, dissect, backref, fast, slow, step, print, at, and pchar to ANSI C style.
  • regex/fnmatch.c
    • Updated function definitions for fnmatch and rangematch to ANSI C style.
  • regex/glob.c
    • Updated function definitions and prototypes for compare, g_Ctoc, g_lstat, g_opendir, g_strchr, g_stat, glob0, glob1, glob2, glob3, globextend, globtilde, globexp1, globexp2, match, qprintf, glob, and globfree to ANSI C style.
  • regex/regcomp.c
    • Updated numerous function definitions including regcomp, p_ere, p_ere_exp, p_str, p_bre, p_simp_re, p_count, p_bracket, p_b_term, p_b_cclass, p_b_eclass, p_b_symbol, p_b_coll_elem, othercase, bothcases, ordinary, nonnewline, repeat, seterr, allocset, freeset, freezeset, firstch, nch, mcadd, mcsub, mcin, mcfind, mcinvert, mccase, isinsets, samesets, categorize, dupl, doemit, doinsert, dofwd, enlarge, stripsnug, findmust, altoffset, computejumps, computematchjumps, and pluscount to ANSI C style.
  • regex/regerror.c
    • Updated function definitions for regerror and regatoi to ANSI C style.
  • regex/regexec.c
    • Updated the function definition for regexec to ANSI C style.
  • regex/regfree.c
    • Updated the function definition for regfree to ANSI C style.
Activity
  • Associated with JIRA ticket RTOS-1233.
  • Automatic testing has already covered these changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great initiative to modernize the codebase by converting old-style K&R C function definitions to ANSI C prototypes. The changes across the various files in the regex directory are largely correct and improve compatibility with modern compilers. I've identified a few areas in glob.c where function signature formatting is inconsistent, leading to long lines that are hard to read. My review comments provide specific suggestions to address these for better code consistency and readability. Overall, a valuable and well-executed refactoring.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

Unit Test Results

9 525 tests   8 933 ✅  52m 31s ⏱️
  583 suites    592 💤
    1 files        0 ❌

Results for commit 176a6a4.

♻️ This comment has been updated with latest results.

@oI0ck oI0ck requested a review from Darchiv March 5, 2026 09:18
@oI0ck oI0ck marked this pull request as ready for review March 5, 2026 09:18
Copy link
Contributor

@julianuziemblo julianuziemblo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nits. I'd consider adding a (nearly) empty .clang-format file to this directory so that the CI doesn't shout at us every time we have make fixes here. Other than those, LGTM.

@oI0ck oI0ck force-pushed the michal.lach/knrregex branch from 7dcd7d4 to f89df4a Compare March 5, 2026 18:19
oI0ck added 2 commits March 5, 2026 20:16
We use a regex implementation from one of BSD's, and it contains
old-style definitions which are being slowly dropped from newer
compilers.

JIRA: RTOS-1233
We use BSD implementation which does not adhere to our coding style.

JIRA: RTOS-1233
@oI0ck oI0ck force-pushed the michal.lach/knrregex branch from b94e44b to 176a6a4 Compare March 5, 2026 19:17
Copy link
Contributor

@julianuziemblo julianuziemblo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

static int g_lstat(Char *fn, struct stat *sb, glob_t *pglob);
static DIR *g_opendir(Char *str, glob_t *pglob);
static Char *g_strchr(Char *str, int ch);
/* static Char *g_strcat(Char *, const Char *); */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep this? Was there any deeper meaning to previous #ifdef notdef of this declaration other than that it was not defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't and there wasn't.
I'm just thinking that it's better not to deviate much from the original code, in case we want to pull changes from upstream implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want to deviate, then maybe let's revert to the original?

Quick look suggests that the notdef seems to be a common pattern in FreeBSD source used instead of if 0:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants